home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / dorskel2.arc / DOORANSI.C < prev    next >
C/C++ Source or Header  |  1991-12-05  |  13KB  |  421 lines

  1. /*
  2.  * Special ANSI input functions (advanced functions; beginners take care)
  3.  * note I've included but not tested these in association with doorskel
  4.  * itself (they were lifted whole from XDB, so they do work).
  5.  * these functions will behave differently if the user doesn't have
  6.  * graphics capabilities, but they'll get by...
  7.  */
  8.  
  9. #include "doorskel.h"
  10.  
  11.  
  12.  
  13.  
  14. char _fastcall ansimenu2 (char tcolor,char color,char *title,
  15.                           char *lineorig,char variable[10][133]) {
  16.  
  17.     /* horizontal framed menu across top of screen selectable by highlighting
  18.        further menu may be pulled down from this menu.  colors are ANSI
  19.        numbers (37 = white).  tcolor is the title/frame color, color is the
  20.        text color of the menus, title is the text for the title in the frame,
  21.        lineorig contains options separated by spaces (use _ within options).
  22.        the variable array contains options like lineorig, one for each
  23.        pull-down menu.  this interfaces to doorhelp.c in a weird but wondrous
  24.        manner :-) by setting the current topic to the first 8 chars of the
  25.        current option and calling help().  Notice that help can't be context-
  26.        sensitive if the user doesn't have graphics capability and this function
  27.        has to emulate a pull-down as a tree-structure...
  28.        for further info you're referred to the XDB source.  This is an advanced
  29.        function and you should avoid it until you feel braver...
  30.  
  31.        Example:
  32.  
  33.         strcpy(var[0]," Help");
  34.         strcpy(var[1],"Select");
  35.         if(gooduser)strcat(var[1]," Create Remove");
  36.         if(sysopuser)strcat(var[1]," New_Index");
  37.         strcat(var[1]," Quit");
  38.         strcpy(var[2],"Key Fields Quit");
  39.         strcpy(var[3],"Field_Names Graphics List_Header Quit");
  40.         strcpy(var[4],"Record_Fields Index_Fields Stats Filters Quit");
  41.         strcpy(var[5],"List Dump Quit");
  42.         strcpy(var[6],"");
  43.         strcpy(var[7],"");
  44.         strcpy(var[8],"");
  45.         strcpy(var[9],"");
  46.         sprintf(s," Database: %s / Index: %-1.38s ",p,index_name(idx));
  47.         strcpy(ss,"Database Index Filter Configure Status Records Quit Help");
  48.         which = ansimenu2(33,36,s,ss,var);
  49.         switch((int)which) {
  50.             ...
  51.     */
  52.  
  53.     register word x,y;
  54.     char nump,numpp;
  55.     char *p[10],*pp[10];
  56.     static char *line = NULL,s[144];
  57.     char helpstring[24];
  58.     word pos[10],ppos[10],pdown,start,temp1,temp2;
  59.     char *t,was,is,temp;
  60.  
  61.     /* Initially display top bar */
  62.  
  63. ReStart:
  64.  
  65.     if(graphics) cls();
  66.     else printm("\n");
  67.     if(line)free(line);
  68.     line = strdup(lineorig);
  69.     if(!graphics) {
  70.         printfm("\n%s\n",title);
  71.     }
  72.     else {
  73.         printfm("\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
  74.         for(x=1;x<((79-strlen(title))/2);x++) printm("═");
  75.         printfm("\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
  76.         curr_cursor(&temp1,&temp2);
  77.         y = temp1;
  78.         for(x = y;x<79;x++) printm("═");
  79.         printm("╗\n");
  80.         curr_cursor(&temp1,&start);
  81.     }
  82.     stripcr(line);
  83.     if (!*line) return 0;
  84.     x=0;
  85.     p[x++]=strtok(line," ");
  86.     while (x<10 && (p[x++]=strtok(0," ")));
  87.     p[--x]=NULL;
  88.     if (!*p) return 0;
  89.     nump=(char)x-1;
  90.     for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';
  91. Over:   /* Redisplay top bar */
  92.     is=was=0;
  93.     for (x=0;x<9;x++) pos[x]=0;
  94.     if(graphics) {
  95.         printfm("\x1b[0;1;%hum",color);
  96.         if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
  97.         fputs("\r",stdout);
  98.         printm("\x1b[2;1H\x1b[K║  ");
  99.     }
  100.     *pos=3;
  101.     if(!graphics) {
  102.         for (x = 0;p[x];x++) {
  103.             curr_cursor(&temp1,&temp2);
  104.             if((temp1 + strlen(p[x]) + 2 + 2) > 77) printm("\n");
  105.             printfm("[%c]%s  ",*p[x],&p[x][1]);
  106.         }
  107.         printm("\b\b: ");
  108.     }
  109.     else {
  110.         printm(*p);
  111.         for (x=1;p[x];x++) {
  112.             printm("  ");
  113.             printm(p[x]);
  114.             pos[x]=pos[x-1]+strlen(p[x-1])+2;
  115.         }
  116.         printm("\x1b[2;79H║\x1b[3;1H\x1b[K╚");
  117.         for(x=1;x<78;x++) printm("═");
  118.         printm("╝\x1b[2;1H");
  119.     }
  120. Next:   /* Move highlight bar */
  121.     if(graphics) {
  122.         if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
  123.         fputs("\r",stdout);
  124.         printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
  125.         printfm("\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[is],p[is],color);
  126.     }
  127.     was=is;
  128. None:   /* Wait for something to happen w/ top bar... */
  129.     if(!graphics) {
  130.         temp=*genin(1,0,1,1,ALLL);
  131.         if(temp=='?') {
  132.             strcpy(helpstring,"MAINHELP");
  133.             set_help(helpstring);
  134.             help();
  135.  
  136.             goto ReStart;
  137.         }
  138.         if(temp)goto Direct;
  139.         else goto None;
  140.     }
  141.     temp=*genin(1,0,0,0,ARROWS);
  142.     switch ((int)temp) {
  143.     case '?':sprintf(helpstring,"%-8u",((is+1)*10));
  144.              set_help(helpstring);
  145.              printg("\x1b[15;1H\x1b[K");
  146.              help();
  147.              goto ReStart;
  148.     case 0:
  149.     case 5:
  150.     case '2': goto GotOne;
  151.     case 1:
  152.     case 4:
  153.     case '4': if (is) is--;
  154.               else is=nump;
  155.               break;
  156.     case 2:
  157.     case '6': if (!p[is+1]) is=0;
  158.               else is++;
  159.               break;
  160.     case 11:
  161.     case 27:  cls();
  162.               *s=0;
  163.               return 0;
  164.     default:
  165. Direct:
  166.               for(x=0;p[x];x++) {       /* Direct select */
  167.                 if(toupper(*p[x])==toupper(temp)) {
  168.                     if(is!=(char)x) {
  169.                         if(graphics) {
  170.                             printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[is],p[is]);
  171.                             printfm("\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[x],p[x],color);
  172.                         }
  173.                     }
  174.                     is=(char)x;
  175.                     goto GotOne;
  176.                 }
  177.               }
  178.               if(!graphics) printm("\b \b");
  179.               break;
  180.     }
  181.     goto Next;
  182.  
  183. GotOne:     /* Pull down actions */
  184.  
  185.     if(!graphics)printm("\n");
  186.     if(!*variable[is]) {  /* No pull downs for this one */
  187.         printg("\x1b[5;1H");
  188.         return ((is+1)*10);
  189.     }
  190.     pdown=pos[is];
  191.     if(pdown>60) pdown=60;
  192.     if(graphics)printfm("\x1b[3;%uH╦\x1b[14C╦\x1b[0m\x1b[0;1;%hum\n",pdown-1,color);
  193.     for(x=0;x<9;x++)ppos[x]=0;
  194.     x=0;
  195.     strcpy(s,variable[is]);
  196.     pp[x++]=strtok(s," ");
  197.     while (x<10 && (pp[x++]=strtok(0," ")));
  198.     pp[--x]=NULL;
  199.     if (!*pp) return 0;
  200.     numpp=(char)x-1;
  201.     for (x=0;pp[x];x++) while (t=strchr(pp[x],'_')) *t=' ';;
  202.     if(!graphics) {
  203.         for (x = 0;pp[x];x++) {
  204.             curr_cursor(&temp1,&temp2);
  205.             if((temp1 + strlen(pp[x]) + 2 + 2) > 77) printm("\n");
  206.             printfm("[%c]%s  ",*pp[x],&pp[x][1]);
  207.         }
  208.         printm("\b\b: ");
  209.     }
  210.     else {
  211.         for(x = 0;pp[x];x++) {
  212.             curr_cursor(&temp1,&ppos[x]);
  213.             printfm("\x1b[K\x1b[%u;%uH║ %-12.12s ║\n",ppos[x],pdown - 1,pp[x]);
  214.         }
  215.         printfm("\x1b[%u;%uH\x1b[K╚══════════════╝",ppos[numpp]+1,pdown-1);
  216.     }
  217.     was=y=0;
  218.  
  219. Over1:  /* Loop until something happens */
  220.  
  221.     if(graphics) {
  222.         printfm("\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[y],pdown,pp[y],color);
  223.         temp=*genin(1,0,0,0,ARROWS);
  224.     }
  225.     else {
  226.         temp=*genin(1,0,1,1,ALLL);
  227.         if(temp=='?') {
  228.             sprintf(helpstring,"%-8u",((is+1)*10));
  229.             set_help(helpstring);
  230.             help();
  231.             goto ReStart;
  232.         }
  233.         if(temp) goto Direct2;
  234.         else goto Over1;
  235.     }
  236.     switch ((int)temp) {
  237.         case '?':sprintf(helpstring,"%-8u",((is+1)*10)+(y+1));
  238.                  set_help(helpstring);
  239.                  printg("\x1b[15;1H\x1b[K");
  240.                  help();
  241.                  goto ReStart;
  242.         case 1:
  243.         case 2:
  244.         case '4':
  245.         case '6': was=is;
  246.                   for(x=0;pp[x];x++) {
  247.                     printfm("\x1b[%u;1H\x1b[K\n",ppos[x]);
  248.                   }
  249.                   printfm("\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
  250.                   printfm("\x1b[3;%uH═\x1b[14C═",pdown-1);
  251.                   if (temp==1 || temp=='4') {
  252.                     if (is) is--;
  253.                     else is=nump;
  254.                   }
  255.                   else {
  256.                     if (!p[is+1]) is=0;
  257.                     else is++;
  258.                   }
  259.                   printfm("\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
  260.                   goto Next;
  261.         case 0:
  262. KeyPress1:
  263.                   printg("\x1b[15;1H");
  264.                   return (((is+1)*10)+(y+1));
  265.         case 4:
  266.         case '8': printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  267.                   if (y) y--;
  268.                   else y=numpp;
  269.                   break;
  270.         case 5:
  271.         case '2': printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  272.                   if (!pp[y+1]) y=0;
  273.                   else y++;
  274.                   break;
  275.         case 11:
  276.         case 27:  for(x=0;pp[x];x++) {
  277.                     printfm("\x1b[%u;1H\x1b[K\n",ppos[x]);
  278.                   }
  279.                   printfm("\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
  280.                   *s=0;
  281.                   printfm("\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
  282.                   for(x=1;x<((79-strlen(title))/2);x++) printm("═");
  283.                   printfm("\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
  284.                   curr_cursor(&temp1,&temp2);
  285.                   temp = (char)temp1;
  286.                   for(x = temp;x < 79;x++) printm("═");
  287.                   printm("╗\n");
  288.                   goto Over;
  289.         default:
  290. Direct2:
  291.                   for(x=0;pp[x];x++) {  /* Direct select */
  292.                     if(toupper(*pp[x])==toupper(temp)) {
  293.                         if(y!=x) {
  294.                             if(graphics)printfm("\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  295.                             if(graphics)printfm("\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[x],pdown,pp[x],color);
  296.                         }
  297.                         y=x;
  298.                         goto KeyPress1;
  299.                     }
  300.                   }
  301.                   if(!graphics)printm("\b \b");
  302.     }
  303.     goto Over1;
  304. }
  305.  
  306.  
  307.  
  308. char _fastcall ansimenu (char color, char *lineorig) {
  309.  
  310.     /* one-line horizontal menu with options selectable by highlighting
  311.        lineorig contains options separated by spaces (use _ within
  312.        options).  color is an ANSI number (37 = white).  example:
  313.          option = ansimenu(32,"Quit Continue");
  314.        This interfaces to doorhelp.c by setting the current topic to
  315.        the first 8 chars of the option and calling help().
  316.        Returns the first character of the option selected, or 0 if
  317.        aborted by the user.  Note that help can't be context-sensitive
  318.        if the user doesn't have graphics capabilities.
  319.     */
  320.  
  321.     register word x = 0;
  322.     static char *line = NULL;
  323.     char *p[36];
  324.     word pos[36],temp1,temp2;
  325.     char helpstring[24],*t,was,is,nump,temp;
  326.  
  327.  
  328. ReStart:
  329.  
  330.     if(line)free(line);
  331.     line=strdup(lineorig);
  332.     stripcr(line);
  333.     if (!strlen(line)) return 0;
  334.     p[x++]=strtok(line," ");
  335.     while (x<34 && (p[x++]=strtok(0," ")));
  336.     p[--x]=NULL;
  337.     if (!*p) return 0;
  338.     nump=(char)x-1;
  339.     for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';;
  340.     printm("\n");
  341.     if (!graphics) goto NoGraph;
  342. Over:
  343.     is=was=0;
  344.     for (x=0;x<35;x++) pos[x]=0;
  345.     printfm("\x1b[0;1;%hum",color);
  346.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  347.     fputs("\r",stdout);
  348.     *pos=1;
  349.     printm("\x1b[1C");
  350.     printm(*p);
  351.     for (x=1;p[x];x++) {
  352.         printm("  ");
  353.         printm(p[x]);
  354.         pos[x]=pos[x-1]+strlen(p[x-1])+2;
  355.     }
  356. Next:
  357.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  358.     fputs("\r",stdout);
  359.     printfm("\x1b[0;1;%hum\x1b[%uC",color,pos[was]);
  360.     printm(p[was]);
  361.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  362.     fputs("\r",stdout);
  363.     printfm("\x1b[7m\x1b[%uC",pos[is]);
  364.     printm(p[is]);
  365.     printfm("\x1b[0;1;%hum",color);
  366.     was=is;
  367. None:
  368.     temp=*genin(1,0,0,0,ARROWS);
  369.     switch((int)temp) {
  370.         case '?':   sprintf(helpstring,"%-8.8s",p[is]);
  371.                     set_help(helpstring);
  372.                     help();
  373.                     goto ReStart;
  374.         case 1:
  375.         case 4:
  376.         case '4':   if(is)is--;
  377.                     else is=nump;
  378.                     break;
  379.         case 0:     return toupper(*p[is]);
  380.         case 5:
  381.         case 2:
  382.         case '6':   if (!p[is+1]) is=0;
  383.                     else is++;
  384.                     break;
  385.         case 3:     printm("\n");
  386.                     goto Over;
  387.         case 11:
  388.         case 27:    return 0;
  389.        default:     for (x=0;p[x]!=NULL;x++) {
  390.                         if (temp==*p[x]) {
  391.                             return toupper(*p[x]);
  392.                         }
  393.                     }
  394.                     break;
  395.     }
  396.     goto Next;
  397.  
  398. NoGraph:
  399.  
  400.     is = was = 0;
  401.     for (x = 0;p[x];x++) {
  402.         curr_cursor(&temp1,&temp2);
  403.         if((temp1 + strlen(p[x]) + 2 + 2) > 77) printm("\n");
  404.         printfm("[%c]%s  ",*p[x],&p[x][1]);
  405.     }
  406.     printm("\b\b: ");
  407.     temp=*genin(1,0,1,1,ALLL);
  408.     if(temp=='?') {
  409.         set_help("RECLINE ");
  410.         help();
  411.         goto ReStart;
  412.     }
  413.     for (x=0;p[x];x++) {
  414.         if (temp==*p[x]) {
  415.             return toupper(*p[x]);
  416.         }
  417.     }
  418.     printm("\nInvalid choice...\n");
  419.     goto NoGraph;
  420. }
  421.